package com.jinmdz.app.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 殡葬业务Provider
 *
 * @author LiCongLu
 * @date 2020-02-06 14:55
 */
public class FuneralBusinessProvider {


    /**
     * 按照业务编码获取未删除的殡葬信息主键
     *
     * @param businessCode 殡葬业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-07 8:53
     */
    public String getFuneralBusinessViewByBusinessCode(@Param("businessCode") String businessCode) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" funeral_business.id,funeral_business.business_code,funeral_business.gmt_create as business_time,funeral_business.version");
                builder.append(" ,funeral_dead.id as dead_id,funeral_dead.dead_name as dead_name,funeral_dead.dead_name_unison as dead_name_unison,funeral_dead.version as dead_version");
                builder.append(" ,family_member.id as member_id,family_member.member_name as member_name,family_member.member_name_unison as member_name_unison,family_member.version as member_version");
                builder.append(" ,family_agent.id as agent_id,family_agent.agent_unit_name as agent_unit_name,family_agent.agent_name as agent_name,family_agent.version as agent_version");
                SELECT(builder.toString());
                FROM(" funeral_business ");
                JOIN(" funeral_dead on funeral_dead.business_code = funeral_business.business_code ");
                JOIN(" family_member on family_member.business_code = funeral_business.business_code ");
                LEFT_OUTER_JOIN(" family_agent on family_agent.business_code = funeral_business.business_code and family_agent.deleted = 0 ");
                WHERE(" funeral_business.deleted = 0 and funeral_dead.deleted = 0 and family_member.deleted = 0");
                WHERE(" funeral_business.business_code = #{businessCode}");
                ORDER_BY(" funeral_business.id desc limit 1");
            }
        }.toString();
    }
}
